<?php 
// +----------------------------------------------------------------------
// | ThinkPHP                                                             
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.      
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>                                  
// +----------------------------------------------------------------------
// $Id$

function showTraceInfo(&$content,$charset,$contentType) {
	if(C('SHOW_PAGE_TRACE')) {
		// 显示页面Trace信息 读取Trace定义文件
		// 定义格式 return array('当前页面'=>$_SERVER['PHP_SELF'],'通信协议'=>$_SERVER['SERVER_PROTOCOL'],...);
		$traceFile	=	CONFIG_PATH.'trace.php';
		 if(file_exists($traceFile)) {
			$_trace	=	include $traceFile;
		 }else{
			$_trace	=	array();
		 }
		 // 系统默认显示信息
		$_trace['当前页面']	=	$_SERVER['PHP_SELF'];
		$_trace['请求方法']	=	$_SERVER['REQUEST_METHOD'];
		$_trace['通信协议']	=	$_SERVER['SERVER_PROTOCOL'];
		$_trace['请求时间']	=	date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']);
		$_trace['用户代理']	=	$_SERVER['HTTP_USER_AGENT'];
		$_trace['会话ID']		=	session_id();
		$_trace['输出编码']	=	$charset;
		if(isset(Log::$log[SQL_LOG_DEBUG])) {
			$log	=	Log::$log[SQL_LOG_DEBUG];
			$_trace['SQL记录']	=	is_array($log)?'['.count($log).']<br/>'.implode('<br/>',$log):'无SQL记录';
		}
		if(isset(Log::$log[WEB_LOG_ERROR])) {
			$log	=	Log::$log[WEB_LOG_ERROR];
			$_trace['错误记录']	=	is_array($log)?'['.count($log).']<br/>'.implode('<br/>',$log):'无错误记录';
		}
		if(isset(Log::$log[WEB_LOG_DEBUG])) {
			$log	=	Log::$log[WEB_LOG_DEBUG];
			$_trace['调试记录']	=	is_array($log)?'['.count($log).']<br/>'.implode('<br/>',$log):'无调试记录';
		}
		$_trace	= auto_charset($_trace,'utf-8');
		$_title		=	auto_charset('页面Trace信息','utf-8');
		// 调用Trace页面模板
		include THINK_PATH.'/Tpl/PageTrace.tpl.php';
	}
	return ;
}
Tag::add('view_end','showTraceInfo');
?>